import { defineStore } from 'pinia'
import http from '@/static/js/request';
import util from '@/static/js/util';

interface ArticleSate {
    userInfo: Record<string, any>
    token: string | null
    temToken: string | null
}
export const useArticleStore = defineStore({
    id: 'userStore',
    state: ():ArticleSate => ({
        userInfo: {},
        token: uni.getStorageSync('accessToken') || null,
        temToken: null
    }),
    getters: {
        
    },
    actions: {
        handleLike(params: Object) {
            new Promise((resolve, reject) => {
                http('post', '/admin/likes', params, (data,msg) => {
                    resolve(data);
                })
            });
        },
        deleteLike(id:String){
            new Promise((resolve, reject) => {
                http('delete', '/admin/likes', [id], (data,msg) => {
                    resolve(data);
                })
            });
        },
        handleFavorite(params:Object) {
            new Promise((resolve, reject) => {
                http('post', '/admin/favorites', params, (data,msg) => {
                    resolve(data);
                })
            });
        },
        deleteFavorite(id:String){
            new Promise((resolve, reject) => {
                http('delete', '/admin/favorites', [id], (data,msg) => {
                    resolve(data);
                })
            });
        },
        sendComment(params:Object){
            new Promise((resolve, reject) => {
                http('post', '/admin/comments', params, (data,msg) => {
                    resolve(data);
                })
            });
        },
        deleteComment(id:String){
            new Promise((resolve, reject) => {
                http('delete', '/admin/comments', [id], (data,msg) => {
                    resolve(data);
                })
            });
        },

    }
})
